<template>
	<view class="container">
		<view class="header">
			<dropDownMenu v-if="show" class="downMenu" :titleArr="titleArr" :dropArr="dropArr" @finishDropClick="finishClick"></dropDownMenu>
			<view class="total">数量：{{ rooms_total }}</view>
		</view>
		<roomList ref="roomList" :query="form" @getTotal="setTotal"></roomList>
		<keyWord :words="form.keyword" @onChange="setKeyWord" />
		<view class="addBtn" @click="add">
			<uni-icons type="plusempty" size="32" color="#fff"></uni-icons>
		</view>
	</view>
</template>

<script>
import api from '@/api/api';
export default {
	data() {
		return {
			form: {
				keyword: '',
				room_type: '3',
				building_id: '0',
				group_id: '',
				community_id: '',
				room_status: '',
				updateNum: 0
			},
			rooms_total: 0,
			current: 0,
			titleArr: ['公寓', '状态', ''],
			dropArr: [[], []],
			show: false
		};
	},
	onLoad() {
		this.show = false;
		this.getBuild();
	},
	onShow() {
		this.form.updateNum++;
	},
	onPullDownRefresh() {
		this.form.updateNum++;
	},
	methods: {
		navChange(e) {
			this.current = e.currentIndex;
		},
		finishClick(resultData) {
			this.form.building_id = resultData[0];
			this.form.room_status = resultData[1];
		},
		add() {
			const _this = this;
			uni.showActionSheet({
				itemList: ['添加整层', '添加整栋', '管理楼栋'],
				success: function (res) {
					if (res.tapIndex == 0) {
						uni.navigateTo({
							url: '/pages/add/floor'
						});
					} else if (res.tapIndex == 1) {
						uni.navigateTo({
							url: '/pages/add/build'
						});
					} else if (res.tapIndex == 2) {
						uni.navigateTo({
							url: '/pages/add/setBuild'
						});
					}
				}
			});
		},
		setKeyWord(e) {
			this.form.keyword = e;
		},
		setTotal(num) {
			this.rooms_total = num;
			uni.stopPullDownRefresh();
		},
		getBuild() {
			api.buildList({}).then((data) => {
				let list = data.data;
				let arr = [];
				for (let i = 0; i < list.length; i++) {
					let base = {
						text: list[i].building_name,
						value: list[i].id
					};
					arr.push(base);
				}
				let all = {
					text: '全部',
					value: ''
				};
				arr.unshift(all);
				this.dropArr[0] = arr;
				this.getDict();
			});
		},
		getDict() {
			api.getDict('room_status').then((data) => {
				let list = data.data;
				let arr = [];
				for (let i = 0; i < list.length; i++) {
					let base = {
						text: list[i].item_name,
						value: list[i].item_code
					};
					arr.push(base);
				}
				let all = {
					text: '全部',
					value: ''
				};
				arr.unshift(all);
				this.dropArr[1] = arr;
				this.show = true;
			});
		}
	}
};
</script>